home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / setpgms.zip / SETDIR.ASM < prev    next >
Assembly Source File  |  1986-12-04  |  6KB  |  347 lines

  1.                page     65,132
  2.  
  3.                ;Copyright 1986, Arnold B. Krueger
  4.                ;All rights reserved. Contact "ARNY KRUEGER"
  5.                ;at the EXEC-PC BBS (414-964-5160) for permission 
  6.                ;to use commercially.
  7.  
  8.                ;SETDIR places the current directory into the
  9.                ;environment variable CURDIR. Usage is:
  10.                ;              SETDIR  [name]
  11.                ;            
  12.                ;              name is the optional name of the
  13.                ;              environment variable set, default: CURDIR.
  14.                ;
  15.                ;You can then reset the current directory using: CD %CURDIR%
  16.                ;This is a faster and more reliable technique than
  17.                ;others involving program pairs (PUSHDIR and POPDIR)
  18.                ;or I/O redirection. (CD >dir.sav).
  19.  
  20.                ;errorlevels are:
  21.                ;               0  if all goes well
  22.                ;               0  if the environment is out of space
  23.                ;                  (an error message will be typed by DOS)
  24.                ;               1 or 2 for SETDIR detected errors:
  25.                ;                    1 - not at DOS 2.0 or above
  26.                ;                    2 - directory string too long
  27.                ;                        (an error message will be typed)
  28.  
  29. code_seg       segment para public
  30.                assume cs:code_seg,ds:code_seg,ss:code_seg,es:code_seg
  31.                extrn   env_set:near
  32.  
  33.                org     80h
  34. psp_parml      db      ?                    ;length of parms
  35. psp_parm       db      ?                    ;actual parms
  36.  
  37.                org     100h                 ; .COM file format
  38. begin:         jmp     main                 ; Skip around data declarations
  39. copyright      db      'Copyright 1986, Arnold B. Krueger GPW, MI 48236'
  40.  
  41. cr             equ     13
  42. lf             equ     10
  43. set_string     db      'CURDIR'
  44. set_length     equ     $-set_string
  45.  
  46. release_error    db    1,'Need at least DOS 2.0 to run SETDIR',cr,lf,'$'
  47. directory_error  db    2,'Directory name too long',cr,lf,'$'
  48.  
  49. main:
  50.         mov      ah,30h              ; get dos release number
  51.         int      21h               
  52.         cmp      al,1                ; above release 1.x
  53.         ja       get_parm            ; if not, don't ask for current directry
  54.  
  55.         mov      si,offset release_error
  56.         jmp      error_exit
  57.  
  58. get_parm:
  59.         cld
  60.         xor      cx,cx
  61.         mov      cl,psp_parml        ;get length of parm
  62.         jcxz     no_parm             ;if none, set default
  63.  
  64.         mov      di,offset psp_parm  ;look at passed parms
  65.         mov      al,' '              ;scan for non-blank
  66.         repz     scasb               ;chop off leading blanks
  67.         jcxz     no_parm
  68.  
  69.         mov      si,di               ;where to send from
  70.         dec      si                  ;back up over non-blank
  71.  
  72.         repnz    scasb               ;scan for blank
  73.                                      ;di points to end of string
  74.         jcxz     got_parm            ;if none found, add '='
  75.  
  76.         dec      di                  ;back up over blank
  77.         jmp      got_parm            ;and add '='
  78.  
  79.  
  80. no_parm:
  81.         mov      cx,set_length       ;how much to move
  82.         mov      di,offset psp_parm  ;where to put stuff
  83.         mov      si,offset set_string;get  CURDIR=
  84.         rep      movsb               ;into my PSP
  85.         mov      si,offset psp_parm  ;where to put stuff
  86. got_parm:
  87.         mov      al,'='
  88.         stosb
  89.         mov      cx,offset main      ;get end of parm string
  90.         sub      cx,di               ;subtract to get avail. length
  91.  
  92.         mov      ah,19h              ; ask for current drive
  93.         int      21h
  94.         add      al,'A'              ; turn into character
  95.         stosb                        ; store into heading area
  96.         dec      cx                  ; cut available length
  97.         mov      al,':'              ; store colon into heading
  98.         stosb                        ; store out colon
  99.         dec      cx                  ; cut available length
  100.  
  101.         mov      al,'\'              ; set root indicator
  102.         stosb                        ; store into heading area
  103.         dec      cx                  ; cut available length
  104.  
  105.         mov      si,di               ; use directory work area
  106.         mov      dl,0                ; specify current drive
  107.         mov      ah,47h              ; ask for current directory
  108.         int      21h                 ; si will point to directory asciiz
  109.  
  110.         xor      al,al
  111.         repnz    scasb               ;look for a zero
  112.  
  113.         jcxz     ld_error            ;if none found, error
  114.  
  115.         mov      ax,di               ;get location of zero
  116.         sub      ax,offset psp_parm  ;get length of parms
  117.         dec      al                  ;knock off length of zero
  118.  
  119.         mov      byte ptr psp_parml,al ;store out length
  120.         mov      si,offset psp_parml
  121.  
  122.         call   env_set
  123.  
  124.         jc     env_error
  125.  
  126. exit:
  127.         mov    ah,4ch                ;terminate program, set errorlevel from al
  128.         int    21h
  129.  
  130. env_error:
  131.         mov    al,2
  132.         jmp    exit
  133.  
  134. ld_error:
  135.         mov    si,offset directory_error
  136.  
  137. error_exit:
  138.         lodsb                        ;reset al with errorlevel
  139.         push   ax                    ;save it
  140.         mov    dx,si                 ;get start of message
  141.         mov    ah,9h                 ;type it out
  142.         int    21h
  143.         pop    ax                    ;reset al with errorlevel
  144.         jmp    exit
  145.  
  146. code_seg ends
  147.          end    begin
  148. 
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263. egin
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  ends
  271.         end    begin
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.         end    begin
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286. nds
  287.         end    begin
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304. ds
  305.         end    begin
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  ends
  319.         end    begin
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.   end    begin
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333. 
  334.      BEGIN
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.